//
//  UpMainTabController.m
//  LoveFreshBee
//
//  Created by wyzc on 16/6/8.
//  Copyright © 2016年 叶落知秋. All rights reserved.
//

#import "UpMainTabController.h"
#import "UpMainNavController.h"
#import "UPHomeViewController.h"
#import "UPOrderViewController.h"
#import "UPFreshReserVationViewController.h"
#import "UPShouCartViewController.h"
#import "UPMyViewController.h"

@interface UpMainTabController ()

@end

@implementation UpMainTabController
//造类的时候调用，只调用一次
+(void)initialize
{
    UITabBarItem *item=[UITabBarItem appearance];
    
    NSDictionary *dict=@{NSForegroundColorAttributeName:UPColor(174, 174, 174),NSFontAttributeName:[UIFont systemFontOfSize:12]};
    [item setTitleTextAttributes:dict forState:UIControlStateNormal];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加home控制器
    UPHomeViewController *homeVC=[[UPHomeViewController alloc]init];
    [self addNavController:homeVC title:@"首页" imageName:@"v2_home" imageName_r:@"v2_home_r"];
    
    
    //添加order控制器
    UPOrderViewController *orderVC=[[UPOrderViewController alloc]init];
    [self addNavController:orderVC title:@"闪送超市" imageName:@"v2_order" imageName_r:@"v2_order_r"];
    
    //添加fresh控制器
    UPFreshReserVationViewController *freshVC=[[UPFreshReserVationViewController alloc]init];
    [self addNavController:freshVC title:@"新鲜预定" imageName:@"freshReservation" imageName_r:@"freshReservation_r"];
    
    //添加shopcart控制器
    UPShouCartViewController *shouCart=[[UPShouCartViewController alloc]init];
    [self addNavController:shouCart title:@"购物车" imageName:@"shopCart" imageName_r:@"shopCart_r"];
    
    //添加my控制器
    UPMyViewController *my=[[UPMyViewController alloc]init];
    [self addNavController:my title:@"我的" imageName:@"v2_my" imageName_r:@"v2_my_r"];
    
    
}

-(void)addNavController:(UIViewController *)controller title:(NSString *)title imageName:(NSString *)imageName  imageName_r:(NSString *)imageName_r
{
    
    UpMainNavController *navVC=[[UpMainNavController alloc]initWithRootViewController:controller];
    [self addChildViewController:navVC];
    
    
    navVC.tabBarItem.title=title;//设置显示的文字
    UIImage *normalImage=[UIImage imageNamed:imageName];

        UIImage *selectedImage=[[UIImage imageNamed:imageName_r]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    
    //设置普通状态下图片
    navVC.tabBarItem.image=normalImage;
    //设置选中状态下图片
    navVC.tabBarItem.selectedImage=selectedImage;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
